home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Arashi 1.1.1 / source code / Game Source / jam src / STFlyThru.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-31  |  5.5 KB  |  288 lines  |  [TEXT/KAHL]

  1. /*/
  2.      Project Arashi: STFlyThru.c
  3.      Major release: Version 1.1d2, 9/5/95
  4.  
  5.      Last modification: Thursday, August 31, 1995, 1:21
  6.      Created: Sunday, February 24, 1991, 2:05
  7.  
  8.      Copyright © 1991-1995, Juri Munkki
  9. /*/
  10.  
  11. #include "VA.h"
  12. #include "STORM.h"
  13. #include "PlayOptions.h"
  14. #include "GamePause.h"
  15. #include <OSUtils.h>    /* mz */
  16.  
  17. #define    MSGDELAY 120    /* 2 seconds */
  18.  
  19. extern    Player        Hero;
  20. extern    EventRecord    Event;
  21.  
  22. static    int            FieldColor;
  23. static    int            SpikeColor;
  24.  
  25. void    MapFlyColors()
  26. {
  27.     register    int        colorbits;
  28.     register    int        i;
  29.     register    ColorSpec    *colp;
  30.                 Handle    FlyColors;
  31.     
  32.     colorbits=0;
  33.     for(i=0;i<5;i++)
  34.     {    colorbits |= 1<<ThisLevel.shColor[i];
  35.     }
  36.     SpikeColor=5;
  37.     FieldColor=6;
  38.  
  39.     for(i=0;i<6;i++)
  40.     {    if((colorbits & (1<<i))==0)
  41.         {    FieldColor=i;
  42.             colorbits |= 1<<i;
  43.             i=6;
  44.         }
  45.     }
  46.  
  47.     for(i=0;i<6;i++)
  48.     {    if((colorbits & (1<<i))==0)
  49.         {    SpikeColor=i;
  50.             colorbits |= 1<<i;
  51.             i=6;
  52.         }
  53.     }
  54.     FlyColors=GetResource('CLOT',ThisLevel.lvColor);
  55.     if (ThisLevel.lvColor == 5)
  56.         FlyColors=GetResource('CLOT',ThisLevel.lvColor + 128);
  57.     HandToHand(&FlyColors);
  58.     colp = (ColorSpec *)*FlyColors;
  59.     colp[SpikeColor]=colp[7];
  60.     colp[FieldColor]=colp[8];
  61.     VASetColors(FlyColors);
  62.     DisposHandle(FlyColors);
  63. }
  64.  
  65. void    RedrawField()
  66. {
  67.     register    int        i,j;
  68.     register    int        oldfield;
  69.     
  70.     oldfield=VA.field;
  71.     VA.field=1;        /*    Field background.        */
  72.     VA.offset=1;    /*    Background                */
  73.  
  74.     for(i=0;i<ww.numsegs;i++)
  75.     {    VAStaticLine(ww.x[i][0],ww.y[i][0],ww.x[i][DEPTH],ww.y[i][DEPTH]);
  76.     }
  77.     if(ww.wraps==0)
  78.         VAStaticLine(ww.x[i][0],ww.y[i][0],ww.x[i][DEPTH],ww.y[i][DEPTH]);
  79.  
  80.     for(j=0;j<=DEPTH;j+=DEPTH)
  81.     {    for(i=0;i<ww.numsegs;i++)
  82.         {    VAStaticLine(ww.x[i][j],ww.y[i][j],ww.x[i+1][j],ww.y[i+1][j]);
  83.         }
  84.     }
  85. }
  86.  
  87. void    FlyGrid()
  88. {
  89.     register    int        i,j;
  90.     register    int        upper,depper;
  91.                 Rect    toclip;
  92.     
  93.     depper=DEPTH-Hero.flydepth;
  94.  
  95.     upper=(depper-DEPTH)/3;
  96.     if(upper<ZOOMDEPTH)
  97.         upper=ZOOMDEPTH;
  98.  
  99.  
  100.     j=ww.numsegs;    
  101.     if(ww.wraps) j--;
  102.     i=j;
  103.     do
  104.     {    
  105.         toclip.left=ww.x[i][upper];
  106.         toclip.top=ww.y[i][upper];
  107.         toclip.right=ww.x[i][depper];
  108.         toclip.bottom=ww.y[i][depper];
  109.  
  110.         if(VAClip(&toclip))
  111.         {    if(Hero.lane==i || Hero.lane+1==i)
  112.             {    VA.color=ThisLevel.shColor[0];
  113.             }
  114.             else
  115.             {    if(i==0 && ww.wraps && Hero.lane == ww.numsegs-1)
  116.                 {    VA.color=ThisLevel.shColor[0];
  117.                 }
  118.                 else
  119.                 {    VA.color=FieldColor;
  120.                 }
  121.             }
  122.  
  123.             VALine(toclip.left,toclip.top,toclip.right,toclip.bottom);
  124.         }
  125.     }    while(i--);
  126.  
  127.     VA.color=FieldColor;
  128.     i=j;
  129.     VAMoveTo(ww.x[ww.numsegs][upper],ww.y[ww.numsegs][upper]);
  130.     do
  131.     {    VASafeLineTo(ww.x[i][upper],ww.y[i][upper]);
  132.     }    while(i--);
  133.  
  134.     i=j;
  135.     VAMoveTo(ww.x[ww.numsegs][depper],ww.y[ww.numsegs][depper]);
  136.     do
  137.     {    VASafeLineTo(ww.x[i][depper],ww.y[i][depper]);
  138.     }    while(i--);
  139. }
  140.  
  141. void DoWatchSpikesMsg()
  142. {
  143.     /* This next section will add the message             */
  144.     /* "Avoid Spikes" to levels 3-8 so the new             */
  145.     /* player will know to avoid them. (mz)             */
  146.     
  147.     unsigned char    *text=(void *)"\pAvoid Spikes";
  148.     long            targetTicks;
  149.     int                x,y;
  150.     
  151.     VA.segmscale = Getfontscale() * 4;
  152.     if(VA.segmscale <=1) 
  153.         VA.segmscale=2;
  154.     x = (int)( (VA.frame.right - 12*(VA.segmscale*3 + 3))/2 );
  155.     y = (int)(VA.frame.bottom/2 - 2);
  156.     VAMoveTo(x,y);
  157.     VA.color=BG1;
  158.     VADrawText((char *)text,1,12);
  159.     
  160.     targetTicks = TickCount() + MSGDELAY;
  161.     /* Now delay for 2 secs.  Update Player and Shots, then erase msg and return */
  162.     while(TickCount() <= targetTicks)
  163.     {
  164.         GameEvent();
  165.         UpdatePlayer();
  166.         UpdateShots();
  167.         UpdateSpikes();
  168.         UpdateCracks(); 
  169.         VAStep();
  170.     }
  171.     VAMoveTo(x,y);
  172.     VA.segmscale = Getfontscale() * 4;
  173.     if(VA.segmscale <=1) 
  174.         VA.segmscale=2;
  175.     VA.color = -1;
  176.     VADrawText((char *)text,1,12);
  177. }
  178.  
  179. void    STFlyThruLoop(Options)
  180. int    Options;
  181. {
  182.     register    int        i;
  183.     
  184.     MapFlyColors();
  185.     VACatchUp();
  186.  
  187.     ThisLevel.totalCount=0;
  188.     ThisLevel.flCount=0;
  189.     ThisLevel.fuCount=0;
  190.     ThisLevel.puCount=0;
  191.  
  192.     for(i=0;i<TANKTYPES;i++)
  193.     {    ThisLevel.tk[i].count=0;
  194.     }
  195.     if(PlayOptions->showfscores)
  196.         UpdateFloatingScores();                /* kill off any floating scores remaining */
  197.     if (ThisLevel.ShowSpikesMsg && Options == NormalPlay)
  198.         DoWatchSpikesMsg();
  199.         
  200. #define    MAKENOISE
  201. #ifdef    MAKENOISE
  202.     PlayA(FlyThru,999);
  203.     if(!PlayOptions->noLoudSounds)
  204.         PlayB(FlyThru,999);
  205. #endif
  206.     
  207.     do
  208.     {    GameEvent();
  209.         if(Event.what == keyDown || Event.what == autoKey)
  210.         {    switch((char)Event.message)
  211.             {    case 'p':
  212.                 case 'P':
  213.                     GamePause(FlythruRunning);
  214.                     break;
  215.             }
  216.         }
  217.         if(Hero.flydepth<DEPTH)
  218.             UpdateShots();
  219.  
  220.         FlyGrid();
  221.         FlySpikes(SpikeColor);
  222.  
  223.         if(Hero.flydepth<DEPTH)
  224.             UpdatePlayer();
  225.         
  226.         UpdateCracks();
  227.         VAStep();
  228.         if(Hero.flydepth==0)
  229.         {    VA.color=-1;    /*    Black                    */
  230.             RedrawField();
  231.             RedrawSpikes();
  232.         }
  233.         Hero.flydepth+=2;
  234.     }    while(!(Hero.flydepth >= DEPTH-ZOOMDEPTH || Hero.state == HeroDead));
  235.  
  236.     while(Hero.state != HeroFlying && Hero.state != HeroDead)
  237.     {    GameEvent();
  238.         UpdatePlayer();
  239.         UpdateCracks();
  240.         VAStep();
  241.     }
  242.  
  243.     if(Hero.state == HeroDead)
  244.     {    VASetColors(GetResource('CLOT',ThisLevel.lvColor));
  245.     }
  246. }
  247.  
  248.  
  249. extern    int    FieldDistance;
  250.  
  251. void    STFlyOutLoop()
  252. {
  253.     short    i;
  254.     
  255.     if (ThisLevel.lvColor != 5)            /* Use alternate grey for invis levels (mz) */
  256.         OpenStars(GetResource('CLOT',ThisLevel.lvColor));
  257.     else
  258.         OpenStars(GetResource('CLOT',ThisLevel.lvColor + 128));
  259.     
  260.     ThisLevel.totalCount=0;
  261.     ThisLevel.flCount=0;
  262.     ThisLevel.fuCount=0;
  263.     ThisLevel.puCount=0;
  264.  
  265.     for(i=0;i<TANKTYPES;i++)
  266.     {    ThisLevel.tk[i].count=0;
  267.     }
  268.     
  269.     if(PlayOptions->showfscores)
  270.     UpdateFloatingScores();            /* kill off any floating scores remaining     */
  271.     
  272.     FieldDistance = 0;
  273.     do
  274.     {    if(FieldDistance == 1)
  275.         {    VA.color=-1;    /*    Black                    */
  276.             RedrawField();
  277.             RedrawSpikes();
  278.             VACatchUp();
  279.         }
  280.         
  281.         FieldRide(&gridOutline,1+(FieldDistance>>2));
  282.         GameEvent();
  283.         VACatchUp();
  284.         VAStep();
  285.     } while(FieldDistance < (DEPTH<<5));
  286.     
  287. }
  288.